package com.orhon.smartcampus.modules.systemctl.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "systemctl_operations", schema = "smartcloud", catalog = "")
public class Operations {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;
    @Column(name = "title", nullable = true)
    private String title;
    @Column(name = "school_id", nullable = true)
    private Long schoolId;
    @Column(name = "created_at", nullable = true)
    private Date createdAt;
    @Column(name = "updated_at", nullable = true)
    private Date updatedAt;
    @Column(name = "deleted_at", nullable = true)
    private Date deletedAt;
    
    
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "operation_id", referencedColumnName = "id")
    @NotFound(action=NotFoundAction.IGNORE)
  	List<OperationApiRelation> operationApiRelations;
    
    @ManyToMany( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
	@JoinTable(name = "systemctl_operation_menu",
	joinColumns = { @JoinColumn(name = "operation_id")}, 
	inverseJoinColumns = { @JoinColumn(name = "menu_id")})
  	List<Menus> Menus;
    
    @ManyToMany( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
	@JoinTable(name = "systemctl_operation_widget",
	joinColumns = { @JoinColumn(name = "operation_id")}, 
	inverseJoinColumns = { @JoinColumn(name = "widget_id")})
  	List<Widgets> widgets;

    @ManyToOne
    @Where(clause = "ISNULL(deleted_at)")
    @JoinColumn(name = "module_id", referencedColumnName = "id")
    @NotFound(action=NotFoundAction.IGNORE)
    private Modules systemctlModulesByModuleId;

    @ManyToOne
    @Where(clause = "ISNULL(deleted_at)")
    @JoinColumn(name = "parent_id", referencedColumnName = "id")
    @NotFound(action=NotFoundAction.IGNORE)
    private Operations systemctlOperationsByParentId;

    @OneToMany(fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
    @JoinColumn(name = "parent_id", referencedColumnName = "id")
    @NotFound(action=NotFoundAction.IGNORE)
    private List<Operations> childreen;
}
